package com.lc.afbx.conn;

import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.http.note.HttpInlet;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/6/12.
 */

@HttpInlet(Conn.INLET_API_MYORDER_PEOPLE)
public class PostApiCasualty extends BaseAsyPost<PostApiCasualty.Info> {

    public String id, type;

    public PostApiCasualty(AsyCallBack<PostApiCasualty.Info> asyCallBack) {
        super(asyCallBack);
    }

    protected Info parser(JSONObject jsonObject) {

        TOAST = jsonObject.optString("message");
        if (jsonObject.optInt("code") == 200) {

            Info info = new Info();
            JSONObject o = jsonObject.optJSONObject("data");

            Data d = new Data();

            d.insurance_type = o.optString("insurance_type");
            d.pstate = o.optString("pstate");
            d.ordersn = o.optString("ordersn");
            d.posttime = o.optString("posttime");
            d.premium = o.optString("premium");
            d.relation = o.optString("relation");
            d.insurance = o.optString("insurance");
            d.store = o.optString("store");

            JSONObject o1 = o.optJSONObject("other_insureds");

            InsurantInfo insurant = new InsurantInfo();
            insurant.idnum = o1.optString("idnum");
            insurant.name = o1.optString("name");
            insurant.cellphone = o1.optString("cellphone");

            JSONObject o2 = o.optJSONObject("applicant_information");

            ApplicantInfo applicant = new ApplicantInfo();
            applicant.idnum = o2.optString("idnum");
            applicant.name = o2.optString("name");
            applicant.cellphone = o2.optString("cellphone");

            JSONArray array1 = o.optJSONArray("death_beneficiary");

            for (int i = 0; i < array1.length(); i++) {

                JSONObject o3 = array1.optJSONObject(i);

                DathInfo dath = new DathInfo();

                dath.name = o3.optString("name");
                dath.benefit_ratio = o3.optString("benefit_ratio");

                d.dathInfoList.add(dath);
            }


            JSONObject o4 = o.optJSONObject("survival_beneficiary");

            LifeInfo life = new LifeInfo();
            life.name = o4.optString("name");
            life.benefit_ratio = o4.optString("benefit_ratio");

            d.lifeInfo = life;

            d.insurant = insurant;
            d.applicant = applicant;

            //TODO  这还没写
            info.data = d;

            return info;
        }
        return null;
    }


    public static class Info {
        public Data data;
    }

    public static class Data {

//        {
//            "code": 200,
//                "message": "成功",
//                "data": {
//            "insurance_type": "交通意外险",
//                    "pstate": "1",
//                    "ordersn": "l201607045451535436",
//                    "posttime": "2016-07-04 14:18:14",
//                    "premium": "3000.00",
//                    "applicant_information": {
//                "name": "张三",
//                        "cellphone": "13111116666",
//                        "idnum": "230103199101016666"
//            },
//            "relation": "1",
//                    "other_insureds": {
//                "name": "张三",
//                        "cellphone": "13111116666",
//                        "idnum": "230103199101016666"
//            },
//            "death_beneficiary": [
//            {
//                "name": "张三",
//                    "benefit_ratio": "100%"
//            },
//            {
//                "name": "王二",
//                    "benefit_ratio": "1%"
//            }
//            ],
//            "insurance": "中国人民保险",
//                    "store": "太平洋保险门店道理分店",
//                    "survival_beneficiary": {
//                          "name": "123",
//                           "benefit_ratio": "100"
//          }
//        }
//        }

        public String insurance_type, pstate, ordersn, posttime, premium, relation, insurance, store;
        public InsurantInfo insurant;
        public ApplicantInfo applicant;
        public List<DathInfo> dathInfoList = new ArrayList<>();
        public LifeInfo lifeInfo;

    }

    public static class InsurantInfo {
        public String name, idnum, cellphone;
    }

    public static class ApplicantInfo {
        public String name, idnum, cellphone;
    }

    public static class DathInfo {
        public String name, benefit_ratio;
    }

    public static class LifeInfo {
        public String name, benefit_ratio;
    }
}
